package com.pengtu.gsj.controller.gcjs;


import javax.servlet.http.HttpServletRequest;


import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.gcjs.YHRoadConstructionA;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.gcjs.YHRoadConstructionAService;
import com.pengtu.gsj.service.system.SystemManageService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

@Controller
@RequestMapping("yHRoadCona")
public class YHRoadConstructionAController extends DefaultBaseController {
	
	@Autowired
	private YHRoadConstructionAService yHRoadConstructionAService;
	
	@Autowired
	private SystemManageService systemManageService;
	
	/**
	 * 
	 * getYHRoadConstructionAs:
	 * 适用:按属性要求获取码表列表
	 * @param page 对象集
	 * @param request
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(value = "list", produces = "application/json; charset=utf-8")
	public Page<YHRoadConstructionA> getYHRoadConstructionAs(Page<YHRoadConstructionA> page,
			HttpServletRequest request) {
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("year");
			page.setOrder(Page.ASC);
		}
		page = yHRoadConstructionAService.findYHRoadConstructionAs(page, queryFilter);
		return page;
	}
	
	/**
	 * 
	 * loadEntity:
	 * 适用: 每个方法执行之前都会执行该方法
	 * @param id  YHRoadConstructionA主键id
	 * @return 返回持久对象YHRoadConstructionA或者新创建对象
	 * @exception 
	 * @since  1.0.0
	 */
	@ModelAttribute
	public YHRoadConstructionA loadEntity(String id){
		YHRoadConstructionA yHRoadConstructionA ;
		if (StringUtils.isNotEmpty(id)) {
			yHRoadConstructionA = yHRoadConstructionAService.getYHRoadConstructionA(id);
		}else {
			yHRoadConstructionA = new YHRoadConstructionA();
		}
		return yHRoadConstructionA;
	}
	
	/**
	 * 
	 * saveYHRoadConstructionA:保存对象
	 * 适用:
	 * @param YHRoadConstructionA 对象
	 * @param request 请求
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveYHRoadConstructionA(@ModelAttribute YHRoadConstructionA yHRoadConstructionA) {
		yHRoadConstructionAService.saveYHRoadConstructionA(yHRoadConstructionA);
		return true;
	}
	
	
	/**
	 * 
	 * deleteYHRoadConstructionA:删除对象
	 * 适用:
	 * @param id
	 * @param attributes
	 * @return 删除是否成功
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean deleteYHRoadConstructionA(String id,RedirectAttributes attributes){
		return yHRoadConstructionAService.deleteYHRoadConstructionA(id);
	}

	
	/**
	 * 
	 * showYHRoadConstructionA:修改对象
	 * 适用:
	 * @param YHRoadConstructionA 对象
	 * @return 对象
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="show")
	@ResponseBody
	public YHRoadConstructionA showYHRoadConstructionA(@ModelAttribute YHRoadConstructionA yHRoadConstructionA){
		return yHRoadConstructionA;
	}
	
	
	/**
	 * 
	 * showYHRoadConstructionAList:返回列表页面
	 * 适用:
	 * @param page
	 * @param request
	 * @param model
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showYHRoadConstructionAList(HttpServletRequest request, Model model) {
		return "gcjs/yHRoadConaList";
	}
	
	/**
	 * checkYear:
	 * 适用:验证路面硬化的年份唯一
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value="checkYear", produces="application/json;charset=utf-8")
	public Boolean checkYear(){
		String year = SpringMvcUtils.getParameter("year");
		String id = SpringMvcUtils.getParameter("id");
		return yHRoadConstructionAService.checkYear(year, id);
	}
}
